#include "centregatewaywidget.h"
#include "ui_centregatewaywidget.h"

CentreGatewayWidget::CentreGatewayWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CentreGatewayWidget)
{
    ui->setupUi(this);
    initUI();
}

CentreGatewayWidget::~CentreGatewayWidget()
{
    delete ui;
}
void CentreGatewayWidget::initUI()
{
    initWidget();
    mainLayout = new QGridLayout;
//    mainLayout = new QVBoxLayout;
    mainLayout->addWidget(ui->groupBox,0,1);
    mainLayout->addWidget(ui->groupBox_2,1,1);
    mainLayout->addWidget(ui->groupBox_3,2,1);

    setLayout(mainLayout);

    connect(ui->comboBox, SIGNAL(activated(QString)),this,SIGNAL(activatedZIgBee(QString)));
    connect(ui->comboBox_2, SIGNAL(activated(QString)),this, SIGNAL(activatedGSM(QString)));
    connect(ui->pushButton, SIGNAL(clicked()),this, SLOT(doZIgbeeButton()));
    connect(ui->pushButton_2, SIGNAL(clicked()),this, SLOT(doGSMButton()));
    connect(ui->pushButton_3, SIGNAL(clicked()),this, SIGNAL(lockSystem()));
    connect(ui->pushButton_4, SIGNAL(clicked()), this, SIGNAL(restartSystem()));
    connect(ui->pushButton_5, SIGNAL(clicked()),this,SIGNAL(shutDownSystem()));
}
void CentreGatewayWidget::addItemsZigbee(const QStringList &names)
{
    ui->comboBox->addItems(names);
    emit activatedZIgBee(ui->comboBox->currentText());
}
void CentreGatewayWidget::addItemsGSM(const QStringList &names)
{
    ui->comboBox_2->addItems(names);
    emit activatedGSM(ui->comboBox_2->currentText());
}
void CentreGatewayWidget::getZigBeeInfo(const QString &fileName, bool onOff)
{
    if (ui->comboBox->currentText() != fileName) {
        return;
    }
    if (!onOff) {
        ui->pushButton->setText(tr("on"));
    }
    else {
        ui->pushButton->setText(tr("off"));
    }
}
void CentreGatewayWidget::getGSMinfo(const QString &fileName, bool onOff)
{
    if (ui->comboBox_2->currentText() != fileName) {
        return;
    }
    if (!onOff) {
        ui->pushButton_2->setText(tr("on"));
    }
    else {
        ui->pushButton_2->setText(tr("off"));
    }
}
void CentreGatewayWidget::doZIgbeeButton()
{
    if (ui->pushButton->text() == "on") {
        emit setZigBeeWorkStatus(ui->comboBox->currentText(),true);
    }
    else {
        emit setZigBeeWorkStatus(ui->comboBox->currentText(),false);
    }
}
void CentreGatewayWidget::doGSMButton()
{
    if (ui->pushButton_2->text() == "on") {
        emit setGSMworkStatus(ui->comboBox_2->currentText(),true);
    }
    else {
        emit setGSMworkStatus(ui->comboBox_2->currentText(),false);
    }
}
void CentreGatewayWidget::initWidget()
{
    QGridLayout *layout1 = new QGridLayout;
    layout1->addWidget(ui->label,0,1,1,1);
    layout1->addWidget(ui->comboBox,0,2,1,2);
    layout1->addWidget(ui->label_2,1,1,1,1);
    layout1->addWidget(ui->pushButton,1,2,1,2);
    ui->groupBox->setLayout(layout1);

    QGridLayout *layout2 = new QGridLayout;
    layout2->addWidget(ui->label_3,0,1,1,1);
    layout2->addWidget(ui->comboBox_2,0,2,1,2);
    layout2->addWidget(ui->label_4,1,1,1,1);
    layout2->addWidget(ui->pushButton_2,1,2,1,2);
    ui->groupBox_2->setLayout(layout2);

    QGridLayout *layout3 = new QGridLayout;
    layout3->addWidget(ui->label_5,0,1,1,1);
    layout3->addWidget(ui->pushButton_3,0,2,1,2);
    layout3->addWidget(ui->label_6,1,1,1,1);
    layout3->addWidget(ui->pushButton_4,1,2,1,2);
    layout3->addWidget(ui->label_7,2,1,1,1);
    layout3->addWidget(ui->pushButton_5,2,2,1,2);
    ui->groupBox_3->setLayout(layout3);
}

